.class public Lcom/burstly/lib/persistance/ResponseSaver;
.super Ljava/lang/Object;
.source "ResponseSaver.java"


# annotations
.annotation system Ldalvik/annotation/Signature;
    value = {
        "<T::",
        "Ljava/io/Serializable;",
        ">",
        "Ljava/lang/Object;"
    }
.end annotation


# static fields
.field private static final LAST_RESPONSE_FOR:Ljava/lang/String; = "last_response_for_"


# instance fields
.field private volatile mAllowedToLoad:Z

.field private volatile mAllowedToSave:Z

.field final mFileHandler:Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Lcom/burstly/lib/persistance/ObjectSaveLoadHandler",
            "<TT;>;"
        }
    .end annotation
.end field

.field private mLastSavedHash:I


# direct methods
.method public constructor <init>(Landroid/content/Context;Ljava/lang/String;)V
    .locals 3
    .parameter "context"
    .parameter "zoneId"

    .prologue
    .line 62
    .local p0, this:Lcom/burstly/lib/persistance/ResponseSaver;,"Lcom/burstly/lib/persistance/ResponseSaver<TT;>;"
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 63
    new-instance v0, Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string v2, "last_response_for_"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-direct {v0, p1, v1}, Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;-><init>(Landroid/content/Context;Ljava/lang/String;)V

    iput-object v0, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mFileHandler:Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;

    .line 64
    return-void
.end method


# virtual methods
.method public deleteLastResponse()V
    .locals 1

    .prologue
    .line 116
    .local p0, this:Lcom/burstly/lib/persistance/ResponseSaver;,"Lcom/burstly/lib/persistance/ResponseSaver<TT;>;"
    iget-object v0, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mFileHandler:Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;

    invoke-virtual {v0}, Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;->delete()V

    .line 117
    return-void
.end method

.method public isAllowedToLoad()Z
    .locals 1

    .prologue
    .line 143
    .local p0, this:Lcom/burstly/lib/persistance/ResponseSaver;,"Lcom/burstly/lib/persistance/ResponseSaver<TT;>;"
    iget-boolean v0, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mAllowedToLoad:Z

    return v0
.end method

.method public isAllowedToSave()Z
    .locals 1

    .prologue
    .line 125
    .local p0, this:Lcom/burstly/lib/persistance/ResponseSaver;,"Lcom/burstly/lib/persistance/ResponseSaver<TT;>;"
    iget-boolean v0, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mAllowedToSave:Z

    return v0
.end method

.method public declared-synchronized loadLastResponse()Ljava/io/Serializable;
    .locals 2
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()TT;"
        }
    .end annotation

    .prologue
    .line 102
    .local p0, this:Lcom/burstly/lib/persistance/ResponseSaver;,"Lcom/burstly/lib/persistance/ResponseSaver<TT;>;"
    monitor-enter p0

    const/4 v0, 0x0

    .line 103
    .local v0, load:Ljava/io/Serializable;,"TT;"
    :try_start_0
    iget-boolean v1, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mAllowedToLoad:Z

    if-eqz v1, :cond_0

    .line 104
    iget-object v1, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mFileHandler:Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;

    invoke-virtual {v1}, Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;->load()Ljava/io/Serializable;

    move-result-object v0

    .line 105
    if-eqz v0, :cond_0

    .line 106
    invoke-virtual {v0}, Ljava/lang/Object;->hashCode()I

    move-result v1

    iput v1, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mLastSavedHash:I
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 109
    :cond_0
    monitor-exit p0

    return-object v0

    .line 102
    :catchall_0
    move-exception v1

    monitor-exit p0

    throw v1
.end method

.method public declared-synchronized saveLastResponse(Ljava/io/Serializable;)V
    .locals 3
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(TT;)V"
        }
    .end annotation

    .prologue
    .line 72
    .local p0, this:Lcom/burstly/lib/persistance/ResponseSaver;,"Lcom/burstly/lib/persistance/ResponseSaver<TT;>;"
    .local p1, response:Ljava/io/Serializable;,"TT;"
    monitor-enter p0

    :try_start_0
    iget-boolean v1, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mAllowedToSave:Z

    if-eqz v1, :cond_0

    if-eqz p1, :cond_0

    .line 73
    invoke-virtual {p1}, Ljava/lang/Object;->hashCode()I

    move-result v0

    .line 74
    .local v0, hash:I
    iget v1, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mLastSavedHash:I

    if-eq v1, v0, :cond_0

    .line 75
    iput v0, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mLastSavedHash:I

    .line 76
    new-instance v1, Lcom/burstly/lib/persistance/ResponseSaver$1;

    invoke-direct {v1, p0, p1}, Lcom/burstly/lib/persistance/ResponseSaver$1;-><init>(Lcom/burstly/lib/persistance/ResponseSaver;Ljava/io/Serializable;)V

    const/4 v2, 0x0

    new-array v2, v2, [Ljava/lang/Void;

    invoke-virtual {v1, v2}, Lcom/burstly/lib/persistance/ResponseSaver$1;->execute([Ljava/lang/Object;)Landroid/os/AsyncTask;

    .line 91
    const/4 v1, 0x0

    iput-boolean v1, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mAllowedToSave:Z
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 94
    .end local v0           #hash:I
    :cond_0
    monitor-exit p0

    return-void

    .line 72
    :catchall_0
    move-exception v1

    monitor-exit p0

    throw v1
.end method

.method public setAllowedToLoad(Z)V
    .locals 0
    .parameter "allowedToLoad"

    .prologue
    .line 152
    .local p0, this:Lcom/burstly/lib/persistance/ResponseSaver;,"Lcom/burstly/lib/persistance/ResponseSaver<TT;>;"
    iput-boolean p1, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mAllowedToLoad:Z

    .line 153
    return-void
.end method

.method public setAllowedToSave(Z)V
    .locals 0
    .parameter "allowedToSave"

    .prologue
    .line 134
    .local p0, this:Lcom/burstly/lib/persistance/ResponseSaver;,"Lcom/burstly/lib/persistance/ResponseSaver<TT;>;"
    iput-boolean p1, p0, Lcom/burstly/lib/persistance/ResponseSaver;->mAllowedToSave:Z

    .line 135
    return-void
.end method
